import paddle


def get_matrix(total_durations_length, durations):
    t = durations.shape[0]
    x = paddle.tile(paddle.to_tensor([1, 0], dtype='int32'), (t, 1)).reshape((1, -1))
    repeats_1 = paddle.to_tensor(durations, dtype='int32').reshape((-1, 1))
    repeats_0 = total_durations_length - repeats_1
    repeats = paddle.concat([repeats_1, repeats_0], axis=1).reshape((-1,))
    results = paddle.repeat_interleave(x, repeats, axis=1)
    return results.reshape((-1, total_durations_length))


import onnx
import onnx.shape_inference
if __name__ == '__main__':
    model = onnx.load('/home/output/inference1/fastspeech2_thorsten.onnx')
    # for n in model.graph.node:
    #     try:
    #         if n.op_type == 'Conv':
    #             # print(n.attribute[0])
    #             # print(n.attribute[1])
    #             print(n)
    #
    #     except AttributeError:
    #         continue
    model1 = onnx.shape_inference.infer_shapes_path('/home/output/inference1/fastspeech2_thorsten.onnx','/home/output/inference1/fastspeech2_thorsten_infered.onnx')